module.exports = function ({ types: t }) {
  return {
    visitor: {
      // Identifier(path, state) {
      //   console.log('Identifier: ', path.node.name)
      // },
      BinaryExpression(path, state) {
        path.replaceWith(t.binaryExpression('+', path.node.left, t.numberLiteral(2)))
      },
      // ReturnStatement(path) {
      //   path.replaceWithMultiple([
      //     t.expressionStatement(t.stringLiteral("Is this the real life?")),
      //     t.expressionStatement(t.stringLiteral("Is this just fantasy?")),
      //     t.expressionStatement(t.stringLiteral("(Enjoy singing the rest of the song in your head)")),
      //   ]);
      // },
      // FunctionDeclaration(path) {
      //   path.replaceWithSourceString(function add(a, b) { return a + b; }); 
      // },
      // // 插入兄弟节点
      // FunctionDeclaration(path) {
      //   path.insertBefore(t.expressionStatement(t.stringLiteral("Because I'm easy come, easy go.")));

      //   path.insertAfter(t.expressionStatement(t.stringLiteral("A little high, little low."))); 
      // },

      // ClassMethod(path) {
      //   path.get('body').unshiftContainer('body', t.expressionStatement(t.stringLiteral('before')));
      //   path.get('body').pushContainer('body', t.expressionStatement(t.stringLiteral('after')));
      // },

      // // 替换
      // ClassDeclaration(path, state) {
      //   if (t.isIdentifier(path.get('extendName'), { name: 'component' }))
      //   // path.siblings(path => t.isReactComponent(path)
      //   path.replaceWithSourceString(`export default witchError(${path.node.name})`)
      // },

      // 添加Error引用
      ModuleDeclare(path, state) {
        if (path.scope.hasBinding('Component')) {

        }
      },
      ModuleDeclare(path, state) {
        if (path.node.source.value === '@liepin/react-violet-mobile') {
          path.insertBefore(t.importDeclaration([], t.stringLiteral('@liepin/react-violet-mobile/lib/input/style')))
        }
      },
      

    }
  }
}

export default function (babel) {
  const { types: t } = babel;
  let paraName = ''
  const updateIdentifier = {
  	Identifier(path) {
      if (path.node.name === paraName) {
        path.node.name = 'xx'
      }
    }
  }
  return {
    name: "ast-transform", // not required
    visitor: {
      FunctionDeclaration(path) {
      	// let param = path.node.params[0]
        // paraName = param.name
        // param.name = 'xx'
        // path.traverse(updateIdentifier)
        path.scope.rename('n', 'aa')
      },
    }
  };
}
